import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../utils/res_colors.dart';
import '../utils/res_images.dart';
import '../utils/screen_adapter.dart';

/// 
/// @Description 
/// @Author WuJianFeng
/// @Date 2024/3/5 14:10
/// 

class SoundDialog extends StatefulWidget{
  const SoundDialog({super.key});

  @override
  State<StatefulWidget> createState() => _SoundDialogState();

  
}

class _SoundDialogState extends State<SoundDialog>{

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    var soundValue = 200.obs;
    var soundCurrentValue = 0;
    var soundTotalValue = 200;
    var pressDown = 0.0;
    return Container(
      child: GestureDetector(
        onVerticalDragDown:(details){
          pressDown = details.localPosition.dy;
          soundCurrentValue = soundValue.value;

        },
        onVerticalDragUpdate: (details){

          var changeValue = pressDown - details.localPosition.dy;

          if((changeValue < -(soundTotalValue - soundCurrentValue) && pressDown < details.localPosition.dy)||
              (changeValue > soundCurrentValue && pressDown > details.localPosition.dy)){
            return;
          }

          soundValue.value = (soundCurrentValue - (pressDown - details.localPosition.dy)).toInt();

        },
        onVerticalDragEnd:(details){

        },

        ///音量组件外框
        child: Container(
          decoration:  BoxDecoration(
            color: Colors.white,
            borderRadius:  BorderRadius.circular(Adapt.pt(16)),
          ),
          width: Adapt.pt(62),
          height: Adapt.pt(272),
          // alignment: Alignment.center,
          child: Stack(
            children: [

              ///音量条灰底
              Positioned(
                child: Align(
                  alignment: Alignment.topCenter,
                  child: Container(
                    height: Adapt.pt(soundTotalValue),
                    margin: EdgeInsets.only(top: Adapt.pt(24)),
                    child: VerticalDivider(
                      color: color_dddddd,
                      //分割线区域的宽度，并非分割线的宽度
                      width: MediaQuery.of(context).size.width,
                      // 分割线真正宽度
                      thickness: Adapt.pt(9),
                    ),
                  ),
                ),
              ),

              ///音量值指示条
              Positioned(
                child: Align(
                  alignment: Alignment.topCenter,
                  child: Obx((){

                    return Container(
                      height: Adapt.pt(soundTotalValue),
                      margin: EdgeInsets.only(top: Adapt.pt(24)),
                      child: VerticalDivider(
                        color: color_6097ef,
                        //分割线区域的宽度，并非分割线的宽度
                        width: MediaQuery.of(context).size.width,
                        // 分割线真正宽度
                        thickness: Adapt.pt(9),
                        indent: Adapt.pt(soundValue.value),
                      ),
                    );
                  }),
                ),
              ),

              ///音量喇叭：白
              Positioned(
                child: Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    margin: EdgeInsets.only(bottom: Adapt.pt(15)),
                    child: ImageUtils.getImgWithSize("sound_0.webp", 25, 25),
                  ),
                ),
              ),

              ///音量喇叭：蓝
              Positioned(
                child: Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    margin: EdgeInsets.only(bottom: Adapt.pt(15)),
                    child: ImageUtils.getImgWithSize("sound_value.webp", 25, 25),
                  ),
                ),
              ),



            ],
          ),
        ),
      ),
    );
  }
  
}
 
 